<html>
	<!--<script type="text/javascript"  src="js/gears_init.js"></script> -->
	<script type="text/javascript"  src="js/Match.js"></script>
	<script type="text/javascript"  src="js/ArrayList.js"></script>
	<script type="text/javascript"  src="js/Integer.js"></script>
	<script type="text/javascript"  src="js/String.js"></script>
	<script type="text/javascript"  src="js/Answer.js"></script>
	<script type="text/javascript"  src="js/AnswerIP.js"></script>
	<script type="text/javascript"  src="js/Match.js"></script>
	<script type="text/javascript"  src="js/IPChoice.js"></script>
	<script type="text/javascript"  src="js/DNSLookup.js"></script>
	<script type="text/javascript"  src="js/Response.js"></script>
	<script type="text/javascript"  src="js/Response.js"></script>
	<script type="text/javascript"  src="js/HistoryLookup.js"></script>
	<embed type="application/x-dependdns" id="pluginId">
	<script>
		var tab_url;
		//var LoockUp = document.getElementById("pluginId");
		var resolverList = new ArrayList();
		var HisDB = new HistoryLookup();
		// set resolver list
		resolverList.add("168.95.1.1");
		resolverList.add("168.95.192.1");
		resolverList.add("139.175.55.244");
		resolverList.add("139.175.252.16");
		resolverList.add("139.175.150.20");
		resolverList.add("139.175.10.20");
		resolverList.add("203.187.0.6");
		resolverList.add("203.133.1.8");
		resolverList.add("211.78.130.1");
		resolverList.add("211.78.130.2");
		resolverList.add("61.56.211.185");
		resolverList.add("211.78.215.200");
		resolverList.add("211.78.215.137");
		resolverList.add("210.200.211.193");
		resolverList.add("210.200.211.225");
		resolverList.add("203.79.224.10");
		resolverList.add("203.79.224.30");

		function display( str )
		{
			//alert(str);
			return null;
		}

		var DepenDNS = {
			start: function() {
				//this.baseurl = chrome.i18n.getMessage("baseurl");
				this.ips = [];
				this.count = 0;
				
			},
			get_domain_from_url: function(url) {
				var Reg = url.match(/http:\/\/(.[^/]+)/);
				if ( Reg != null )
					return  url.match(/http:\/\/(.[^/]+)/)[1]
				else 
					return null;
			},
			run: function(tab) {
/*
				this.domain = this.get_domain_from_url(tab.url);
				if ( this.domain == null )
					return false;
				var ResolveAns = new Array();
				var oneTimeCount = new Array;
		
				for ( var i = 0 ; i < resolverList.size() ; i++ ){
					var Res = resolverList.get(i);
					var tmp = LoockUp.SendQuery(this.domain,Res);
					oneTimeCount.push(tmp.length);
					ResolveAns.push(tmp);
				}

				var dnslookup = new DNSLookup();
				dnslookup.setQuery(this.domain);
				dnslookup.setResolver(resolverList);
				HisDB.setDomainName(this.domain);
				HisDB.setResolveAnswer(ResolveAns);
				HisDB.run(this.domain);
				var count_string = 0;
				var His = HisDB.getHistoryList();
				count_string = dnslookup.doLookup(ResolveAns,oneTimeCount,His);
				count_string = count_string/10 + '';*/
				count_string = '10';
				delete dnslookup;
				delete ResolveAns;
				delete oneTimeCount;
				chrome.browserAction.setBadgeBackgroundColor( {color:[208, 0, 24, 255]} );
				chrome.browserAction.setIcon({path: "icon/icon_22.png"});
				this.badge(count_string,tab);
			},
			badge: function(text,tab) {
				var obj = new Object();
				obj.text = text;
				obj.tabId = tab.id;
				chrome.browserAction.setBadgeText(obj);
			},

		};  // end of DepenDNS  
		DepenDNS.start();
		websql();
		//testArrayList();	
		chrome.tabs.onSelectionChanged.addListener(function(tabid,selectedInfo){
			chrome.tabs.get(tabid,function(tab) {
				DepenDNS.run(tab);
			});
		});

		chrome.windows.onFocusChanged.addListener(function(windowId) {
			chrome.tabs.getSelected(windowId, function(tab) {
				DepenDNS.run(tab);
			});
		});


		chrome.tabs.onUpdated.addListener(function(tabId, change, tab) {
			// make sure the tab hasn't changed...
			chrome.tabs.getSelected(null, function(tab) {
				DepenDNS.run(tab);
			});
		});

		// Message passing between background and popup
		var port = chrome.extension.connect({name: "parse_url"});
		chrome.extension.onConnect.addListener(function(port) {
			console.assert(port.name == "parse_url");	
			port.onMessage.addListener(function(msg) {
				if ( msg.popup == "URL" ){
					//alert(msg.popup);
					port.postMessage({BackGround: DepenDNS.domain});
				}
			});
		});

		function displayMyResult(rs)
		{
			alert(rs);
		};

		function displayMyError(err)
		{
			alert(err);
		};

		var db;
		function websql(){
			var success = false;
			try{
				db = window.openDatabase("dependns", "1.1", "DepenDNS History Database",  1024 * 1024);	
				if( !db )
					alert('Could not create database: ');
			}
			catch (ex){
				alert('Could not create database: ' + ex.message);
			}
		};

		
	</script>
	<!-- <body onload="init()">
		<img id="icon" src="/icon/icon_22.png">
		<canvas id="canvas" width="22" height="22">
	</body> -->
</html>



